package com.xuzhijie.pms.utils;

import cn.hutool.core.util.IdcardUtil;
import cn.hutool.core.util.RandomUtil;
import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.Claim;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.github.javafaker.Faker;
import com.xuzhijie.pms.entity.Administrator;
import com.xuzhijie.pms.mapper.AdministratorMapper;
import com.xuzhijie.pms.service.IAdministratorService;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;

import java.util.Base64;
import java.util.Map;

@Component
public class saltUtil {


    public static String generateSalt() {
        return RandomUtil.randomString(16);
    }

    public static String encodePassword(String password, String salt) {
        String saltedPassword = password + salt;

        try {
            MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
            byte[] hashedBytes = messageDigest.digest(saltedPassword.getBytes());
            return Base64.getEncoder().encodeToString(hashedBytes);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static void main(String[] args) {



    }

    //        System.out.println(generateSalt());
    //        System.out.println(encodePassword("xzj20020902","cos88771o92o3bbk"));
    //        String token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJVOTBINzhIOTgiLCJleHAiOjE3MDcyOTg0NDh9.ChS5TKoDRYouyZYIfxujPZf6cdWPCwZu9RnlcAbEoy8";
    //        DecodedJWT decodedJWT = JWT.decode(token);
    //        Map<String, Claim> claims = decodedJWT.getClaims();
    //        System.out.println(claims);
    //        Claim userIdClaim = claims.get("sub");
    //        String userId = userIdClaim.asString();
    //        System.out.println(userId);
}
